package com.zw.pdm.module.file.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.production.FileSheet;
import com.zw.pdm.module.basic.service.DictCommonService;
import com.zw.pdm.module.file.service.FileAddService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.zw.pdm.constant.Constant.FILE_TYPE;
import static com.zw.pdm.constant.Constant.GROUP_SPECTYPE;

/**
 * @author mayongfeng
 * @version 1.0.0
 * @ClassName CreateFileController.java
 * @Description TODO
 * @createTime 2020年12月12日 15:22:00
 */
@Controller
@RequiresPermissions("all")
@RequestMapping("create/file")
public class FileAddController extends BaseController {

    @Autowired
    private DictCommonService dictCommonService;
    @Autowired
    private FileAddService fileAddService;

    /**
     * @Author mayongfeng
     * @Date 8:52 2020/12/14
     * @Description 导航栏跳转创建存档清单页面
     *
     **/
    @GetMapping("add")
    @RequiresPermissions(value = {"file:found:view"}, logical = Logical.OR)
    public String addFile(Model model){
        model.addAttribute("specials",dictCommonService.findDictByGroupName(GROUP_SPECTYPE));
        model.addAttribute("fileypes", dictCommonService.findDictByGroupName(FILE_TYPE));
        return "file/add/addFile";
    }

    /**
     * @Author mayongfeng
     * @Date 8:52 2020/12/14
     * @Description 保存存档功能
     *
     **/
    @PostMapping("first/save")
    @ResponseBody
    @RequiresPermissions(value = {"file:found:save"}, logical = Logical.OR)
    public JsonResult firstFileSave(FileSheet fileSheet, String[] fileName, Integer[] picecNum, Integer[] pageNum, String[] remark){

        int i = fileAddService.firstFileSave(fileSheet,fileName,picecNum,pageNum,remark);
        if(-2==i){
            return JsonResult.success("当前项目下的专业和部分已经提报过了！请走补存流程！",-2);
        }

        return jsonResult(i);
    }




}
